<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>网络管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">

		function checkValidate()
		{

			var subnetName=document.getElementById("subnetName").value;

			var subnetPoolObj=document.getElementById("subnetpoolId");
			var subnetPoolId=subnetPoolObj.options[subnetPoolObj.selectedIndex].value;


			//判断是否为空

			if(subnetName==null||subnetName=="")
			{
				window.alertx("请输入子网名称！");
				return false;
			}
			if(subnetPoolId=='')
			{
				window.alertx("请选择一个子网池！");
				return false;
			}





		}
		function chooseSubnetPool(subnetPools)
		{
			var id=subnetPools.options[subnetPools.selectedIndex].value;
			if(id!='')
			{
				var ipVersion=document.getElementById(id).value;
				document.getElementById("ipVersion").value=ipVersion;
				if(ipVersion=='4')
					document.getElementById("subnetPoolIpVersion").value="IPv4";
				else
					document.getElementById("subnetPoolIpVersion").value="IPv6";
				<%--$.ajax({--%>
					<%--type: "POST",--%>
					<%--url: "${ctx}/scene/sceneNetwork/getIPversion",--%>
					<%--data: {--%>
						<%--subnetPoolId:subnetPools.options[subnetPools.selectedIndex].value--%>
					<%--},--%>
					<%--success:function(ipVersion){--%>
						<%--document.getElementById("ipVersion").value=ipVersion;--%>
						<%--if(ipVersion=='4')--%>
							<%--document.getElementById("subnetPoolIpVersion").value="IPv4";--%>
						<%--else--%>
							<%--document.getElementById("subnetPoolIpVersion").value="IPv6";--%>


					<%--},--%>
					<%--error:function(){--%>
						<%--alertx("error");--%>
					<%--}--%>
				<%--});--%>
			}



		}
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});

	</script>
</head>
<body>
<ul class="nav nav-tabs">
	<li><a href="${ctx}/scene/sceneNetwork/subnetManage?id=${sceneNetwork.id}">子网列表</a></li>
	<li class="active"><a href="${ctx}/scene/sceneNetwork/createSubnet?id=${sceneNetwork.id}">创建子网</a></li>
</ul><br/>
<form id="inputForm" action="${ctx}/scene/sceneNetwork/saveSubnet" method="post" class="form-horizontal">
	<sys:message content="${message}"/>
	<input type="hidden" id="id" name="id" value="${sceneNetwork.id}">

	<div id="subnet">
		<div class="control-group">
			<label class="control-label">子网名称：</label>
			<div class="controls">
				<input type="text" id="subnetName" name="subnetName" htmlEscape="false" maxlength="64" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">地址资源池:</label>

			<div class="controls">
				<select id="subnetpoolId" name="subnetpoolId" onchange="chooseSubnetPool(this)" class="input-xlarge">
					<option value=""selected>===请选择===</option>
					<c:forEach items="${spList}" var="sp">
						<c:forEach items="${sp.spPrefixes}" var="spPrefix">
							<option value="${sp.spId}">${sp.spName}(${spPrefix})</option>
						</c:forEach>

					</c:forEach>
				</select>
				<c:forEach items="${spList}" var="sp">
					<input type="hidden" id="${sp.spId}" value="${sp.spIpVersion}"/>
				</c:forEach>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">IP版本：</label>
			<div class="controls">
				<input type="hidden" value="4" id="ipVersion" name="ipVersion"/>
				<input type="text" id="subnetPoolIpVersion" name="subnetPoolIpVersion" htmlEscape="false" maxlength="64" class="input-xlarge " value="IPv4" readonly>
			</div>
		</div>
	</div>


	<div class="form-actions">
		<shiro:hasPermission name="scene:sceneNetwork:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存" onclick=" return checkValidate()"/>&nbsp;</shiro:hasPermission>
		<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
	</div>
</form>
</body>
</html>